<?php namespace sacvoyage;

require_once("util.php");
use \Exception;

/*
 * represents a javascript-object
 */
class Object extends \stdClass {

	/*
	 * 
	 */
	public function __construct($mixed=null) {
		if($mixed===null) {
			// do nothing
		} elseif(is_object($mixed) || is_associative_array($mixed)) {
			$this->loadIterator($mixed);
		} else {
			throw new Exception('object must be constructed of json-string, object or associative array');
		}
	}

	public function hasAttr($name) {
		$attrs = get_object_vars($this); 
    	return array_key_exists($name, $attrs); 
	}
	
	/*
	 * 
	 */
	public function clear() {
		foreach($this as $key=>$val) {
			unset($this->{$key});
		}
	}



	/*
	 * 
	 */
	public function loadIterator($iterator) {
		$this->clear();
		foreach($iterator as $key=>$value) {
			$this->{$key}=$value;
		}
	}
	
	
	
	
	
	
}

?>
